package com.example.team.controller;

import com.example.team.entity.Leaves;
import com.example.team.service.ILeavesService;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Date;
/***
 * 编写者:王轩
 * 时间:2023/10/23
 * 描述:请假管理
 */
@RestController
@Api(tags = "请假管理系统")
public class LeavesController {
    @Autowired
    private ILeavesService leavesService;
    @RequestMapping(value = "/Leaves",method = {RequestMethod.GET})
    public String Leaves(){
        return "请假信息管理系统";
    }
    //添加请假申请
    @ApiOperation(value = "添加请假申请")
    @RequestMapping(value = "/insterLeaves",method = {RequestMethod.GET})
    public  Integer insterLeaves(Integer LeaveID, Integer EmployeeID, String LeaveReason,
                                 @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
                                 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
                                 Date StartDate,
                                 @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
                                     Date EndDate){
        Leaves leaves=new Leaves();
        leaves.setLeaveID(LeaveID);
        leaves.setEmployeeID(EmployeeID);
        leaves.setReason(LeaveReason);
        leaves.setStartDate(StartDate);
        leaves.setEndDate(EndDate);
        return leavesService.insertLeaves(leaves);
    }
    //添加请假批准人姓名
    @ApiOperation(value = "添加请假批准人姓名")
    @RequestMapping(value = "/insterApprover",method = {RequestMethod.GET})
    public  int insterApprover(Integer LeaveID, String Ratifiers){
        Leaves leaves =new Leaves();
        leaves.setLeaveID(LeaveID);
        leaves.setRatifiers(Ratifiers);
        return leavesService.insterApprover(leaves);
    }
    //删除方法
    @ApiOperation(value = "删除请假信息")
    @RequestMapping(value = "/deleteLeaves",method = {RequestMethod.GET})
    public Integer deleteLeaves(Integer LeavesId){
        Leaves leaves=new Leaves();
        leaves.setLeaveID(LeavesId);
        return leavesService.deleteLeaves(leaves);
    }
    //修改方法
    @ApiOperation(value = "修改请假信息")
    @RequestMapping(value = "/updateLeaves",method = {RequestMethod.GET})
    public Integer updateLeaves(Leaves leaves){
        return leavesService.updateLeaves(leaves);
    }
    //查询方法
    @ApiOperation(value = "查询所有请假信息")
    @RequestMapping(value = "/getAllLeaves",method = {RequestMethod.GET})
    public List<Leaves>getAllLeaves(Leaves leaves){
        return leavesService.getAllLeaves(leaves);
    }
}
